package com.qidian.buy.util;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author 郭浩
 */
@Service
public class MyTest {
    public static void main(String[] args) {
        ArrayList list = new ArrayList<>(3);

        try {
            System.out.println(getListLength(list));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static int getListLength(ArrayList list) throws Exception{
        Class<ArrayList> clazz = ArrayList.class;
        Field data = clazz.getDeclaredField("elementData");
        data.setAccessible(true);
        Object[] objects = (Object[]) data.get(list);
        return objects.length;
    }

}
